package com.zb.spring5.ioc.inteface.impl;

import com.zb.spring5.ioc.inteface.MessageProvider;
import com.zb.spring5.ioc.inteface.MessageRender;

public class StandardOutMessageRender implements MessageRender {

    private MessageProvider messageProvider;

    public StandardOutMessageRender() {
        System.out.println("--> StandardOutMessageRender: constructor called");
    }

    @Override
    public void render() {
        if (messageProvider == null)
        {
            throw new RuntimeException("you must set property messageProvider of class:"+StandardOutMessageRender.class.getName());
        }
        System.out.println(messageProvider.getMessage());
    }

    @Override
    public void setMessageProvider(MessageProvider messageProvider) {
        System.out.println("--> StandardOutMessageRender: setting the provider");
        this.messageProvider = messageProvider;
    }

    @Override
    public MessageProvider getMessageProvider() {
        return this.messageProvider;
    }
}
